<?php


namespace app\admin\controller;


use app\common\controller\AdminUserBase;
use app\common\model\ForumCate;
use think\facade\Request;
use think\Validate;

class Forum extends AdminUserBase
{
    /**
     * 分类
     */
    public function cate(){
        if (Request::isAjax()){
            $param = input();
            $where = [];
            $data = ForumCate::where($where)->select();
            $this->result($data);
        }
        return view('forum/cate/index');
    }
    public function cate_form(){
        $id = input('id');
        $data = ForumCate::get($id);
        $this->assign('data',$data);
        return view('forum/cate/form');
    }
    public function cate_save(){
        $param = input();
        $model = new ForumCate();

        $validate = Validate::make([
            'name|名称'  => 'require|unique:forum_cate',
        ]);

        if (!$validate->check($param)) {
            $this->error($validate->getError());
        }

        if (empty($param['id'])){
            $param['admin_id'] = session('admin.id');
            $res = $model->allowField(true)->isUpdate(false)->save($param);
            saveAdminLog("添加论坛分类");
        }else{
            $res = $model->allowField(true)->isUpdate(true)->save($param,['id'=>$param['id']]);
            saveAdminLog("编辑论坛分类");
        }

        if ($res !== false){
            $this->success();
        }else{
            $this->error();
        }
    }
    public function cate_del(){
        $id = input('id');
        $res = ForumCate::destroy($id);
        if ($res !== false){
            saveAdminLog("删除论坛分类");
            $this->success();
        }else{
            $this->error();
        }
    }
    /**
     * 分类
     */
}
